<template>
	<view class="">
		<view class="flex-column justify-center align-center" style="padding-top: 90px;">
			<view>
				<image src="/static/img/首页.png" style="width: 300rpx;height: 250rpx;" mode="widthFix"></image>
				<view class="color1 text-center sub-size fw-700">物流</view>
			</view>
			<view class="size mt-30 color1" style="margin-top: 180px;">
				申请获得以下权限
			</view>
			<view class="mt-10 small-size color1">
				获得你的公开信息（手机号码）
			</view>
			<view class="" style="margin-top: 60rpx;"></view>
			<u-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" text="手机号快捷登录" shape="circle"
				:customStyle="{'width':'80%','color':$u.color.color}"></u-button>
			<view @click="aa" class="mt-30 small-size mt-30 color1">
				暂不授权
			</view>
			<view class="mt-30">
				<u-radio-group v-model="value">
					<u-radio shape="square" label="我已阅读并同意" labelColor="#fff"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getUserMobile,
		getOpenid
	} from '@/common/api.js'
	export default {
		data() {
			return {
				value: ""
			};
		},
		onLoad() {
			//手机号码啊破解也需要code而且具有时效
			// 获取解密本机手机号码的信息
			// this.updateSessionKey()
		},
		methods: {
			aa() {
				uni.reLaunch({
					url: '/pages/home/home'
				})
			},
			getPhoneNumber(e) {
				let vm = this;
				uni.login({
					provider: 'weixin',
					success: async (res) => {
						console.log('code', res);
						getOpenid({
							data: {
								code: res.code
							}
						}).then(res => {
							console.log(res);
							let params = {
								iv: e.detail.iv,
								encryptedData: e.detail.encryptedData,
								sessionKey: res.session_key,
								openid: res.openid
							}

							getUserMobile(params).then(res => {
								console.log(res);
								uni.hideLoading();
								vm.$refs.uToast.show({
									type: 'success',
									message: '授权成功',
									complete() {
										uni.hideLoading()
										console.log('res', res);
										vm.$store.commit("setUserInfo", res.userinfo);
										vm.show = false;
										uni.reLaunch({
											url: '/pages/home/home'
										})
									}
								})
							})
						})
					}
				})
			}

		}
	};
</script>

<style>
	page {
		background-color: rgb(42, 187, 174);
	}
</style>